package com.diao.myhub.model.vo;

import com.diao.myhub.exception.ICustomizeError;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

import java.io.Serializable;

@Data
public class BaseResponse<T> implements Serializable {
    private int code;
    private String msg;
    private T data;

    public static <T> BaseResponse<T> ok(T data) {
        BaseResponse<T> response = new BaseResponse<>();
        response.setCode(200);
        response.setData(data);
        return response;
    }
    public static BaseResponse<String> ok() {
        BaseResponse<String> response = new BaseResponse<>();
        response.setCode(200);
        response.setData("ok");
        return response;
    }

    public static BaseResponse<Object> error() {
        BaseResponse<Object> response = new BaseResponse<>();
        response.setCode(500);
        response.setMsg("系统异常!");
        return response;
    }

    public static BaseResponse<Object> error(String msg) {
        BaseResponse<Object> response = new BaseResponse<>();
        response.setCode(500);
        response.setMsg(msg);
        return response;
    }

    public static BaseResponse<Object> error(int code, String msg) {
        BaseResponse<Object> response = new BaseResponse<>();
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }
    public static BaseResponse<Object> error(ICustomizeError customizeError) {
        BaseResponse<Object> response = new BaseResponse<>();
        response.setCode(customizeError.errorCode());
        response.setMsg(customizeError.getMsg());
        return response;
    }

}
